/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.item.action;

import org.w3c.dom.Element;

import com.lineage.server.PacketCreate;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.item.L1Item;
import com.lineage.server.utils.Random;

/**
 * Class <code>L1ItemAddMpAction</code> 道具动作:加魔.
 * 
 * @author jrwz
 * @version 2012-6-23上午04:31:50
 * @see com.lineage.server.model.item.action
 * @since JDK1.7
 */
public final class L1ItemAddMpAction extends L1ItemXmlAction {

    /** 加魔:基本. */
    private final int addMp;
    /** 加魔:最高. */
    private final int maxMp;

    /**
     * 道具动作:使用效果.
     * 
     * @param element
     *            - XML 文档中的一个元素
     */
    public L1ItemAddMpAction(final Element element) {
        super(element);
        this.addMp = L1ItemXmlParser.getIntAttribute(element, "基本", 0);
        this.maxMp = L1ItemXmlParser.getIntAttribute(element, "最高", 0);
    }

    @Override
    public L1Item execute(final L1PcInstance pc, final L1ItemInstance useItem,
            final int readC1, final int readC2, final int targetId,
            final int targetX, final int targetY) {
        // UsePotion_AddMp.get().useItem(pc, item, 0, this.addMp, 0, 0);
        pc.delAbsoluteBarrier(); // 删除绝对屏障效果
        final int r = this.maxMp - this.addMp;
        final int randomMp = (Random.nextInt(r) + 1) + this.addMp; // 随机加魔量
        pc.setCurrentMp(pc.getCurrentMp() + randomMp); // 为角色增加MP
        PacketCreate.get().sendSinglePackets(pc, "你的 魔力 渐渐恢复。");
        return null;
    }
}
